import ReactDOM from 'react-dom';

import { WeaLicenseSubmit } from 'weaPortalPublic';

import store from './stores';
import Login from './components/login';
import Theme from './components/theme';
import E7FormCloud from './components/login/e7login/formCloud';
import E8FormCloud from './components/login/e8login/formCloud';

// 执行主题相关方法
window.doThemeAction = (actionName, params = {}, callback) => {
  const portalThemeStore = store.portalThemeStore;

  if (actionName == 'onLoadMain') {
    // 加载内容区域
    portalThemeStore.onLoadMain(params, callback);
  } else if (actionName == 'onLogout') {
    // 退出
    portalThemeStore.onLogout(params, callback);
  } else if (actionName == 'onLeftMenuModeChange') {
    // 展开收缩左侧菜单
    portalThemeStore.onLeftMenuModeChange(params.leftMenuMode, callback);
  } else if (actionName == 'onQuickSearch') {
    // 快捷搜索跳转
    portalThemeStore.onQuickSearch(params, callback);
  } else if (actionName == 'onLoadEmailMenu') {
    // 加载邮件菜单
    portalThemeStore.onLoadEmailMenu(params, callback);
  } else if (actionName == 'onThemeChange') {
    // 修改主题
    portalThemeStore.onThemeChange(params, callback);
  } else if (actionName == 'onThemeTsChange') {
    // 修改特色门户主题
    portalThemeStore.onThemeTsChange(params, callback);
  } else if (actionName == 'onColorChange') {
    // 修改主题颜色
    portalThemeStore.onColorChange(params, callback);
  } else if (actionName == 'onLayoutChange') {
    // 修改主题布局
    portalThemeStore.onLayoutChange(params, callback);
  } else if (actionName == 'getAccount') {
    // 刷新账号栏
    portalThemeStore.getAccount(params, callback);
  } else if (actionName == 'onLoadLeftMenuCount') {
    // 加载左侧菜单统计数
    portalThemeStore.onLoadLeftMenuCount(params, callback);
  }
};

// 加载左侧菜单统计数
window.loadLeftMenuCount = (params, callback) => {
  window.doThemeAction('onLoadLeftMenuCount', params, callback);
};

// 提交license
window.doLicenseSubmit = () => {
  const div = document.createElement('div');
  document.body.appendChild(div);
  ReactDOM.render(<WeaLicenseSubmit ecId={`${(this && this.props && this.props.ecId) || ''}_WeaLicenseSubmit@wv6e5n`} visible={true} from="login" />, div);
};

module.exports = { store, Login, Theme, E7FormCloud, E8FormCloud };
